require("../css/introduce.less")
document.ready(function(){
    // 获取dom
    let frequency=document.querySelector("#frequency")
    let headImg=document.querySelector("#headImg")
    let introduceTxt=document.querySelector("#introduceTxt")
    let name=document.querySelector("#name")
    let time=document.querySelector("#time")
    let peoplenum=document.querySelector("#peoplenum")
    let calorie=document.querySelector("#calorie")
    let start=document.querySelector("#start")
    let back=document.querySelector("#back")

    // 返回上一级
    back.addEventListener("click",function(){
        history.go(-1)
    })

    let courseId=window.location.search.split("?")
    console.log(courseId);
    localStorage.setItem("courseId",courseId[1])
    // let userId=JSON.parse(localStorage.getItem("user")).userId
    axios.get(window.$utils.url+`/sports/courseDetail?id=${courseId[1]}`)
    .then(function(res){
        let ret=res.data
        console.log(ret);
        if (ret.status==0) {
            localStorage.setItem("fragments",JSON.stringify(ret.data.fragments))

            show(ret.data)
        }
    })
    .catch(function(err){
        console.log(err);
    })

    // 渲染数据
    function show(arr){
        frequency.textContent=arr.frequency
        headImg.src=window.$utils.url+arr.imgurl
        introduceTxt.textContent=arr.desc
        name.textContent=arr.name
        time.textContent=arr.time
        peoplenum.textContent=arr.peoplenum
        calorie.textContent=arr.calorie
    }
    start.addEventListener("click",function(){
        location.href="./player.html"
    })
})